//
//  TopNavagation.m
//  BeautifulLockerRoom
//
//  Created by mac on 16/7/28.
//  Copyright © 2016年 Winny. All rights reserved.
//

#import "TopNavagation.h"
#define LOGOIMAGE @"home_page_titleimage"
#define LOGOWIDTH WINDOWWIDTH / 4


@implementation TopNavagation

-(instancetype)init
{
    self = [super init];
    if (self)
    {
        self = [[TopNavagation alloc]initWithFrame:CGRectMake(0, 0, WINDOWWIDTH, 64)];
        self.backgroundColor = [UIColor redColor];
        [self topView];
    }
    return self;
    
}
#pragma mark - 视图排版
-(void)topView
{
    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 9+20, LOGOWIDTH, 30)];
    image.image = [UIImage imageNamed:LOGOIMAGE];
    
    UIImageView * image1 = [[UIImageView alloc]initWithFrame:CGRectMake(LOGOWIDTH + +25, 31.5, 20, 20)];
    image1.image = [UIImage imageNamed:@"image_titlebar_searchsub"];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(LOGOWIDTH + 20, 20+4 ,WINDOWWIDTH - LOGOWIDTH + 20 - 80, 36);
    [button setBackgroundColor:TOPBUTTONCOLOR];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [RequestTool getNetworkRequestWithUrl:MAINMENUURL date:^(NSDictionary * dic)
     {
         NSDictionary * data = [dic objectForKey:@"data"];
         self.topTitle = [data objectForKey:@"search_text"];
         button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
         [button setTitle:[NSString stringWithFormat:@"       %@",self.topTitle] forState:UIControlStateNormal];
         
         [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
         
         UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
         button1.frame = CGRectMake(WINDOWWIDTH - 37, 26, 30, 30);
         button1.backgroundColor = [UIColor clearColor];
         [button1 setImage:[UIImage imageNamed:@"image_titlebar_message"]forState:UIControlStateNormal];
         [button1 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
         
         [self addSubview:button1];
         [self addSubview:button];
         [self addSubview:image];
         [self addSubview:image1];
         
         
     }];
    
    
   
}
-(void)buttonClick:(UIButton *)sender
{
    
}
@end
